package com.jy.oms.framework.asyn.task.checker;

import com.jy.oms.framework.asyn.task.checker.model.ExecutorCheckParam;
import com.jy.oms.framework.asyn.task.checker.model.ExecutorCheckResult;
import com.jy.oms.framework.asyn.task.collector.TaskExclusiveStateCollector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 排他任务校验，一个时间点同一类任务只有一个可以执行
 *
 * @author liuquan
 */
@Service
public class TaskExclusiveChecker implements IExecutorChecker {

    @Autowired
    private TaskExclusiveStateCollector taskExclusiveStateCollector;

    @Override
    public ExecutorCheckResult canExecute(ExecutorCheckParam executorCheckParam) {
        boolean canExecute = taskExclusiveStateCollector.canExecute(
                executorCheckParam.getExecutorCode(), executorCheckParam.getBillCode());
        ExecutorCheckResult checkResult = new ExecutorCheckResult();
        checkResult.setResult(canExecute);
        return checkResult;
    }
}
